package com.rd.student.dashuju.wangbo.exercise0728;

import java.io.*;

public class TestBuffered {

    public static void main(String[] args) throws IOException {
        File file = new File("stream.txt");
        FileInputStream fis = new FileInputStream(file);
        InputStream is = new BufferedInputStream(fis);
        byte[] arr = new byte[(int) file.length()];
        is.read(arr);
        System.out.println(new String(arr));
        is.close();
        fis.close();
        copyFile("stream.txt","streamBuffered.txt");
    }

    public static void copyFile(String srcPath,String destPath) throws IOException {
        InputStream is = new BufferedInputStream(
                new FileInputStream(srcPath));
        OutputStream os = new BufferedOutputStream(
                new FileOutputStream(destPath));
        byte[] bytes = new byte[1024];
        int len = 0;
        while ((len = is.read(bytes)) != -1){
            os.write(bytes,0,len);
        }
//        强制刷新
        os.flush();
        os.close();
        is.close();

    }
}
